<?php


namespace App\Api\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;


class PromotionBargainRecord extends Model
{
    use HasFactory;

    protected $guarded = [];
    protected $table = 'cmc_promotion_bargain_record';

    public function member()
    {
        return $this->belongsTo(Member::class,'member_id','member_id');
    }

    public static function saveBar($data)
    {
        return self::query()->insertGetId($data);
    }

    /**
     * 查询用户帮砍次数
     * @param $where
     * @param $help_member_id
     * @return mixed
     */
    public static function helpNum($where, $helpMemberId)
    {
        return self::where($where)->where('help_member_id', $helpMemberId)->count();
    }

    /**
     * 查询当前砍价的金额
     * @param $where
     * @return mixed
     */
    public static function old_price($where)
    {
        return self::where($where)->orderBy('old_price', 'asc')->value('old_price');
    }

    /**
     * 查询当前剩余看价次数
     * @param $where
     * @return mixed
     */
    public static function old_num($where)
    {
        return self::where($where)->orderBy('old_num', 'asc')->value('old_num');
    }


    public static function barRecord($where,$field)
    {
        return self::where($where)->orderBy('bargain_time','asc')->get($field)->toArray();
    }
}
